<?php
require_once 'DAO/Banco.php';
require_once 'Model/Area.php';

class DAOArea extends Banco{
    
    function getAreas(){
        $areas = array();
        Banco::conecta();
        $banco = Banco::getBanco();
        $query = $banco->query("SELECT * FROM V_AREA ORDER BY ARE_DESCRICAO");
        if(!empty($query)){
            while ($cid = $query->fetch_assoc() ) {
                $area = new Area();  
                $area->setCodigo($cid['ARE_CODIGO']);
                $area->setDescricao($cid['ARE_DESCRICAO']);
                $areas[] = (object)$area;
            }
        }
        $banco->close();
        return $areas;
    }
    
    function getArea($codigo){
        $area = NULL;  
        Banco::conecta();
        $banco = Banco::getBanco();
        if ($sql = $banco->prepare("SELECT ARE_CODIGO, ARE_DESCRICAO FROM TB_AREA WHERE ARE_CODIGO = ?")) {
            $sql->bind_param('i',$codigo);
            $sql->execute();
            $sql->bind_result($id, $descricao);
            while ($sql->fetch()) {
                $area = new Area();
                $area->setCodigo($id);
                $area->setDescricao($descricao);
            }
            $sql->close();
        }
        $banco->close();
        return $area;
    }
}

?>
